package serveur.agence;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import prog.AgenceImp;
import prog.AgenceItf;


public class ServeurAgence {
	/* le parametre 0 est la ville */
	public static void main(String[] args) throws Exception {
		AgenceImp agenceImp = new AgenceImp(args[0]);
		AgenceItf agenceItf = (AgenceItf) UnicastRemoteObject.exportObject(agenceImp, 1099);
		Registry registry = LocateRegistry.createRegistry(1099);
		registry.rebind(args[0].toUpperCase(), agenceItf);
		
		/****** TEST ******/
		Registry registry4;
		try {
			registry4 = LocateRegistry.getRegistry(1099);
			System.out.println("Creation 1099");
		} catch (RemoteException e) {
			registry4 = LocateRegistry.createRegistry(1099);
		}
		registry4.rebind("MARSEILLE", agenceItf);
		
		Registry registry3 = LocateRegistry.getRegistry(1099);
		AgenceItf agenceItf2 = (AgenceItf) registry.lookup("PARIS");
		
		agenceItf2.test();
		/****** TEST ******/
	}
}
